package com.bdqn.service.common;

import com.bdqn.mapper.common.AppInfoMapper;
import com.bdqn.pojo.AppInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class AppInfoServiceImpl implements AppInfoService {
    @Resource
    private AppInfoMapper appInfoMapper;

    @Override
    public List<AppInfo> appInfoList(String softwareName, Long status, Long flatformId, Long categoryLevel1, Long categoryLevel2, Long categoryLevel3, Integer pageIndex, Integer pageSize) {
        pageIndex = (pageIndex - 1) * pageSize;
        return appInfoMapper.appInfoList(softwareName, status, flatformId, categoryLevel1, categoryLevel2, categoryLevel3, pageIndex, pageSize);
    }

    @Override
    public int pageCount(String softwareName, Long status, Long flatformId, Long categoryLevel1, Long categoryLevel2, Long categoryLevel3, Integer pageIndex, Integer pageSize) {
        pageIndex = (pageIndex - 1) * pageSize;
        return appInfoMapper.pageCount(softwareName, status, flatformId, categoryLevel1, categoryLevel2, categoryLevel3, pageIndex, pageSize);
    }

    @Override
    public List<AppInfo> appList(String softwareName, Long flatformId, Long categoryLevel1, Long categoryLevel2, Long categoryLevel3, Integer pageIndex, Integer pageSize) {
        pageIndex = (pageIndex - 1) * pageSize;
        return appInfoMapper.appList(softwareName,flatformId,categoryLevel1,categoryLevel2,categoryLevel3,pageIndex,pageSize);
    }

    @Override
    public int pageCountMgr(String softwareName, Long flatformId, Long categoryLevel1, Long categoryLevel2, Long categoryLevel3, Integer pageIndex, Integer pageSize) {
        pageIndex = (pageIndex - 1) * pageSize;
        return appInfoMapper.pageCountMgr(softwareName,flatformId,categoryLevel1,categoryLevel2,categoryLevel3,pageIndex,pageSize);
    }

    @Override
    public AppInfo getApp(Long id) {
        AppInfo appInfo = appInfoMapper.getApp(id);
        if (appInfo != null){
            return appInfo;
        }
        return null;
    }

    @Override
    public boolean updateById(Long id, Long status) {
        if (appInfoMapper.updateById(id,status) > 0){
            return true;
        }
        return false;
    }

    @Override
    public boolean APKNameExist(String APKName) {
        if (appInfoMapper.APKNameExist(APKName) == 1){
            return true;
        }
        return false;
    }

    @Override
    public boolean addAppInfo(AppInfo appInfo) {
        if (appInfoMapper.addAppInfo(appInfo) == 1){
            return true;
        }
        return false;
    }

    @Override
    public boolean updateAppInfo(AppInfo appInfo) {
        if (appInfoMapper.updateAppInfo(appInfo) == 1){
            return true;
        }
        return false;
    }

    @Override
    public boolean updateAppVersionNo(Long id, Long versionId) {
        if (appInfoMapper.updateAppVersionNo(id,versionId) == 1){
            return true;
        }
        return false;
    }

    @Transactional
    @Override
    public boolean del(Long id) {
        if (appInfoMapper.del(id)>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean updateSale(String onSaleDate, String offSaleDate,Long id,Long status) {
        if (appInfoMapper.updateSale(onSaleDate,offSaleDate,id,status) == 1){
            return true;
        }
        return false;
    }

    @Override
    public boolean delLogo(Long id) {
        if (appInfoMapper.delLogo(id)==1){
            return true;
        }
        return false;
    }
}
